package com.demo.data.other;

/**找出出现第二多的元素
 * @author Ziroom
 *
 */
public class FindChar {

	private static Character[] chars = new Character[]{'a', 'b', 'c', 'd', 'a', 'd', 'a'};
	
	public static void main(String[] args) {
		int max = 0;
		int bigger = 0;
		Character biggerChar = null;
		for (int i=0; i<chars.length; i++) {
			int count = 1;
			Character tmpChar = chars[i];
			if(tmpChar != null) {
				chars[i] = null;
				for(int j=i+1; j<chars.length; j++) {
					if(chars[j]!= null && tmpChar == chars[j]) {
						chars[j] = null;
						count++;
					}
				}
				if(count >= max) {
					max = count;
				}else if(count >= bigger) {
					bigger = count;
					biggerChar = tmpChar;
				}
			}
		}
		
		System.out.println(biggerChar);
	}
	
}
